package com.ruoyi.type.controller;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.vo.TypeWithStrategyVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.type.domain.Type;
import com.ruoyi.type.service.ITypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 类型表Controller
 *
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/type")
public class TypeController extends BaseController
{
    @Autowired
    private ITypeService typeService;

    /**
     * 查询类型表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Type type)
    {

        System.out.println("=============================");
        System.out.println("=============================");
        System.out.println("---------------"+type);
        System.out.println("=============================");
        startPage();
        return getDataTable(typeService.selectTypeList(type));
    }

    /**
     * 导出类型表列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, Type type)
    {
        ExcelUtil<TypeWithStrategyVo> util = new ExcelUtil<TypeWithStrategyVo>(TypeWithStrategyVo.class);
        util.exportExcel(response, typeService.selectTypeList(type) , "类型表数据");
    }

    /**
     * 获取类型表详细信息
     */

    @GetMapping(value = "/selectOne/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(typeService.selectTypeById(id));
    }

    /**
     * 新增类型表
     */

    @PostMapping("/add")
    public AjaxResult add(@RequestBody Type type)
    {
        return toAjax(typeService.insertType(type));
    }

    /**
     * 修改类型表
     */

    @PutMapping("/update")
    public AjaxResult edit(@RequestBody Type type)
    {
        return toAjax(typeService.updateType(type));
    }

    /**
     * 删除类型表
     */

	@DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(typeService.deleteTypeByIds(ids));
    }
}
